import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/page/takeoutManagement/page/businessSetting/page/timeRange/widget/time_wheel_scroll_view.dart';
import 'package:boss/ui/widget/center_title_app_bar.dart';
import 'package:boss/ui/widget/label_button.dart';
import 'package:flutter/material.dart';
import 'package:router/annotation.dart';

import 'model/hour_minute.dart';
import 'widget/time_range_title.dart';

@RouterConfig(TimeRangePage.pageName)
class TimeRangePage extends StatefulWidget {
  static const pageName = '/timeRangePage';

  @Autowired()
  final HourMinute start;

  @Autowired()
  final HourMinute end;

  const TimeRangePage({Key key, this.start, this.end}) : super(key: key);

  @override
  _TimeRangePageState createState() => _TimeRangePageState();
}

class _TimeRangePageState extends State<TimeRangePage> {
  HourMinute start;
  HourMinute end;

  @override
  void initState() {
    super.initState();

    start = widget.start ?? HourMinute(0, 0);
    end = widget.end ?? HourMinute(23, 59);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CenterTitleAppBar(
        title: '选择时间',
        actions: <Widget>[
          LabelButton(
            title: '保存',
            onTap: () {
              Navigator.pop(context, [start, end]);
            },
            textStyle: TextStyleConstant().blue_28,
          ),
        ],
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          TimeRangeTitle('营业时间'),
          TimeWheelScrollView(
            initValue: start,
            onChanged: (hourSecond) {
              start = hourSecond;
            },
          ),
          TimeRangeTitle('休息时间'),
          TimeWheelScrollView(
            initValue: end,
            onChanged: (hourSecond) {
              end = hourSecond;
            },
          ),
        ],
      ),
    );
  }
}
